def is_prime(n):

    if n <= 1:
        return False

    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False

    return True


def get_closest_prime(n):

    if is_prime(n):
        return n

    
    next_prime = n + 1
    while not is_prime(next_prime):
        next_prime += 1

    
    prev_prime = n - 1
  
def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


words_to_nums = {
    "zero": "0", "one": "1", "two": "2", "three": "3", "four": "4",
    "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"
}


words = input().split()


if len(words) != 3:
    print("Wrong input")
else:
    
    number = "".join([words_to_nums.get(word, "") for word in words])

    
    if number.isnumeric() and len(number) == 3:
        number = int(number)

        
        lower_prime = number
        upper_prime = number
        while True:
            if is_prime(lower_prime):
                print(lower_prime)
                break
            if is_prime(upper_prime):
                print(upper_prime)
                break
            lower_prime -= 1
            upper_prime += 1
    else:
        print("Wrong input")
